package com.reone.jsbridgedemo.activity.base;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.reone.jsbridgedemo.activity.CmdActivity;
import com.reone.jsbridgedemo.activity.MainActivity;
import com.reone.jsbridgedemo.activity.SecondActivity;
import com.reone.jsbridgedemo.activity.X5WebViewActivity;

import java.util.ArrayList;

/**
 * Created by wangxingsheng on 2018/7/20.
 */
public class ListActivity extends android.app.ListActivity {
    private ArrayList<Class> clz = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        clz.add(MainActivity.class);
        clz.add(SecondActivity.class);
        clz.add(X5WebViewActivity.class);
        clz.add(CmdActivity.class);
        setListAdapter(listAdapter);
    }

    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        super.onListItemClick(l, v, position, id);
        startActivity(new Intent(this,clz.get(position)));
    }

    private BaseAdapter listAdapter = new BaseAdapter() {
        @Override
        public int getCount() {
            return clz.size();
        }

        @Override
        public Class getItem(int position) {
            return clz.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            @SuppressLint("ViewHolder")
            TextView textView = (TextView) LayoutInflater.from(ListActivity.this).inflate(android.R.layout.simple_list_item_1, parent, false);
            textView.setText(getItem(position).getSimpleName());
            return textView;
        }
    };
}
